package com.tianqu.tms.www.attn.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Attn;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.www.attn.controller.AttnDeatilListController;
import com.tianqu.tms.www.attn.viewhelper.AttnViewhelper;
import com.tianqu.tms.www.member.controller.MemberUDTopListController;
import com.tianqu.tms.www.member.viewhelper.MemberUDViewHelper;

/**
 * @author zhangxueliang
 * 经办人用户一览
 */
public class AttnDetailListAction extends TmsAction{
	public final static String PAGENO = "pageNo";
	public final static String SORTKEY = "sortKey";
	public final static String MAXINDEX = "maxIndex";
	public final static String ASC = "asc";
	private Logger logger = Logger.getLogger(AttnDetailListAction.class);
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		//从数据库中查询出列表信息,封装到list中迭代
		AttnViewhelper view = new AttnViewhelper();
		if(request.getParameter(PAGENO) == null) {
			uc.setAttribute(PAGENO, view.getPageNo());
			uc.setAttribute(SORTKEY, view.getSortKey());
			uc.setAttribute(MAXINDEX, view.getMaxIndex());
			uc.setAttribute(ASC, view.getAsc());
		} else {
			uc.setAttribute(PAGENO, request.getParameter(PAGENO));
			uc.setAttribute(SORTKEY, request.getParameter(SORTKEY));
			uc.setAttribute(MAXINDEX, request.getParameter(MAXINDEX));
			uc.setAttribute(ASC, request.getParameter(ASC));
		}
		AttnDeatilListController controller = new AttnDeatilListController();
		controller.execute(uc);
		view = (AttnViewhelper)uc.getAttribute(TmsConstants.VIEWHELP);
		Attn attn = (Attn)uc.getAttribute(MemberUDTopListController.PAGING);
		// viewhelp中设置翻页。
		view.setPageNo(Integer.toString(attn.getPageNo()));
		view.setMaxIndex(Integer.toString(attn.getMaxIndex()));
		view.setAsc(Boolean.toString(attn.isAsc()));
		view.setSortKey(Integer.toString(attn.getSortKey()));
		view.setTotalCount(Integer.toString(attn.getTotalCount()));
		view.setDateFrom(Integer.toString(attn.getDateFrom()));
		view.setDateTo(Integer.toString(attn.getDateTo()));
		
		
		request.setAttribute(TmsConstants.VIEWHELP, view);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
